package conf

import (
	"encoding/json"
	"game-server/log"
	"io/ioutil"
	"os"
	"fmt"
)

var Server struct {
	LogLevel    string
	LogPath     string
	WSAddr      string
	CertFile    string
	KeyFile     string
	TCPAddr     string
	MaxConnNum  int
	ConsolePort int
	ProfilePath string
	Host        string
	User        string
	Passwd      string
	Db          string
	MaxIdle     int
	MaxOpen     int
	Cache       string
	BaseNum     int32
	Redis       string
	RedisDb     string
	HeartBeat   int
	RoomCron    int
	RoomTimeOut int64
	UserCron    int
	UserTimeOut int64
	DataToMysql int
	CheckCard   string
	MaxBoomTime   int32
	MinBoomTime   int32
	AnswerTime  int64
	AnswerTimeOut int64
}

func init() {
	goPath := os.Getenv("GOPATH")
	fmt.Println("goPath",goPath)
	if goPath != "" {
		path := goPath + "/bin/conf/server.json"
		fmt.Println("path",path)

		data, err := ioutil.ReadFile(path)
		if err != nil {
			log.Error("%v", err)
		}
		err = json.Unmarshal(data, &Server)
		if err != nil {
			log.Error("%v", err)
		}
		fmt.Println("Server",Server)
	} else {
		data, err := ioutil.ReadFile("conf/server.json")
		if err != nil {
			log.Error("%v", err)
		}
		err = json.Unmarshal(data, &Server)
		if err != nil {
			log.Error("%v", err)
		}
	}
}
